! B don't require optional com.google.gson package#769
! B don't require optional com.google.gson package#769
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideGeneralizes JsonApprovals’ Gson-related overloads to avoid a hard dependency on com.google.gson, while preserving behavior via generics and casts, and updates tests and documentation metadata accordingly. Class diagram for generalized JsonApprovals Gson overloadsclassDiagram
class JsonApprovals {
+static void verifyJson(String json, boolean reorderJson)
+static void verifyJson(String json, boolean reorderJson, Options options)
+static <T> void verifyJson(String json, boolean reorderJson, Function1Generic gsonBuilder)
+static <T> void verifyJson(String json, boolean reorderJson, Function1Generic gsonBuilder, Options options)
+static void verifyAsJson(Object o)
+static void verifyAsJson(Object o, Options options)
+static <T> void verifyAsJson(Object o, Function1Generic gsonBuilder)
+static <T> void verifyAsJson(Object o, Function1Generic gsonBuilder, Options options)
}
class JsonUtils {
+static String reorderFields(String json, Function1Generic gsonBuilder)
+static String prettyPrint(String json, Function1Generic gsonBuilder)
+static String asJson(Object o, Function1Generic gsonBuilder)
}
class Approvals {
+static void verify(String formattedJson, Options options)
}
class Options {
+Options forFile()
+Options withExtension(String extension)
}
class Function1Generic {
+TOut apply(TIn input)
}
JsonApprovals ..> JsonUtils
JsonApprovals ..> Approvals
JsonApprovals ..> Options
JsonApprovals ..> Function1Generic
JsonUtils ..> Function1Generic
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
I asked my genie to try out your fix in the starter project where I've a repdocuring branch when using module system. Genie says: I tested this against a JPMS consumer project (module-info.java present) — which is what chicory in #768 uses. Good news: This does fix the Bad news: The JPMS compilation still fails with: The root cause is broader than gson — with JPMS, the compiler eagerly resolves ALL types in the jar. Every optional dependency that appears in a class signature causes the same problem. I created #770 to track the full scope of this. I think we need to discuss the approach with Llewellyn before merging a partial fix, since there are trade-offs here (this loses type safety on the I also pushed a reproduction branch to the StarterProject: https://github.com/approvals/ApprovalTests.java.StarterProject/tree/reproduce-jpms-issue-770 |
Fixes #768
Summary by Sourcery
Relax JsonApprovals’ dependency on Gson by generalizing its builder callbacks, while keeping existing behavior intact.
Enhancements:
Tests: